<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 5 Transitional//EN">
<%@ page pageEncoding="UTF-8" %>
<%@ page import="jp.co.technotree.apl.api.common.Message,jp.co.technotree.common.ApplicationManager" %>
<%@page import="jp.co.technotree.apl.cmd.inventory.Inv2000Bean"%>
<jsp:useBean id="formBean" class="jp.co.technotree.apl.cmd.inventory.Inv2000Bean" scope="request" />
<%@page import="jp.co.technotree.apl.api.common.FwCom"%>
<%
ApplicationManager appMng = ApplicationManager.getInstance();	//アプリケーションマネージャの取得（パス等）
	String strOutputCate = formBean.getOutputCate(); //1=初回モード 2=入荷中モード 3=完了モード 4=キャンセルモード 5=参照モード
%>
<html>
<head>


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="apple-mobile-web-app-capable" content="yes"/>
<!-- 数字を電話番号にさせない -->
<meta name="format-detection" content="telephone=no"/>
<link rel='stylesheet' type='text/css' href='../../common/css/inventory/inv2000.css' >
<script type='text/javascript' src='../../common/js/NumKeyBoard.js'></script>

<!--ポップアップ用-->
<link rel='stylesheet' type='text/css' href='../../common/css/popUp.css' >
<script type='text/javascript' src='../../common/js/popUp.js'></script>

<style type="text/css">

	.mainTbl_Left{
		 border: 0px solid #CCCCFF;
		 height:150px;
		 width: 210px;
		 margin-top:-250px;
		 align:center;
	}

	.mainTbl_Right{
		 border: 0px solid #CCCCFF;
		 height:550px;
	}


	.confirmBtn {
		width: 80px;
		height:50px;
		font-size:18px;
	}

	.orderCompletionBtn {
		width: 120px;
		height:40px;
		font-size:18px;
	}

	.confirmBtn2 {
		width: 120px;
		height:50px;
		font-size:18px;
	}


	.confirmBtn3 {
		width: 170px;
		height:50px;
		font-size:18px;
	}

	.selTitle{
	 font-size:16px;
	 valign:middle;

	}

	.ImageZone{
	 position:absolute;
	 top :90px;
	 right:160px;
	 visibility: visible;

	 width: 200px;
	 height:200px;
	}



	.OrderReason{
	 position:absolute;
	 top :100px;
	 left:660px;
	 visibility: visible;

	 width: 300px;
	 height:200px;
	}
	
	.ReadStyle{
		 background-color:#CCC;
	}
	
	
	img {
     max-height:170px;
     max-width:330px;
     height :auto;
     width :auto;
    } 


</style>



<script language='javascript'>

//画面固定
//document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);

function onInit(){
	//入荷完了後、メッセーを出してメイン画面に遷移
	var stateFlg = "<%=formBean.getStateFlg()%>";
	var afterFunc="nextPageJump('odr3000');"
	if(stateFlg == "4"){
		//入荷処理を正常に完了しました
		alert_Info2("<%=Message.getMessage("INF00020").replace("$1", "入荷取消")%>",afterFunc);
	}
}


//-------------------------------------------------------------------------
//<!-- ポップアップ START -->

//パップアップ解除
function back(){
	document.getElementById("opAlertBtn").style.display = "none";
	document.getElementById("opAlert").style.display = "none";
	document.getElementById("opAlertButton").style.display = "none";
	document.getElementById("opAlertTop").style.display = "none";
	document.getElementById("allbackgr").style.display = "none";
}

//<!-- ポップアップ END -->
//-------------------------------------------------------------------------



function nextPageJump(nextPage){

	mainForm = document.getElementById("F1");
	document.getElementById("nextPage").value = nextPage;

	mainForm.submit();
}


//戻るボタン押下
function backBtn(nextPage){

	mainForm = document.getElementById("F1");
	document.getElementById("nextPage").value = nextPage;

	mainForm.submit();
}



//「入荷取消」ボタン押下
function undoBtn(){
	
	//確定時と入荷時の更新日を比較
	mRsvSupplyCheck();

}



function JSONConvert(node){
	var type = node.nodeType;
	if ( isTextNode(node) ){
		var text = getTextValue(node);
		return text;
	}
	if ( type==1 ){
		var json = {};
		var nodeName = node.nodeName;
		var childs = node.childNodes;

		for (var i = 0; i<childs.length; i++){
			var child = childs[i];
			var obj = json[child.nodeName];

			if ( child.nodeType == 1 ){
				if ( obj ){
					var array = null;
					if ( !isArray(obj) ){
						array=[];
						array[array.length]=obj;
					}else{
						array=json[child.nodeName];
					}
					array[array.length]=JSONConvert(child);
					json[child.nodeName]=array;
				}else{
					json[child.nodeName]=JSONConvert(child);
				}
			}
		}
		return json;
	}
}

function isTextNode(node){
	if ( node.hasChildNodes() ){
		var childs = node.childNodes;
		for (var i = 0; i<childs.length; i++){
			var child = childs[i];
			if ( child.nodeType != 3 ) return false;
		}
	}
	return true;
}

function getTextValue(node){
	if ( node.hasChildNodes() ){
		var childs = node.childNodes;
		var child = childs[0];
		if ( child.nodeType == 3 ){
			return child.nodeValue;
		}
	}
	return null;
}
//------------------------------------------------------------------------------

//*************************************************
//AJAX 部分(予備品Mから削除＆在庫チェックチェック)
//*************************************************
function mRsvSupplyCheck(btnCate){
	
	var findItemNo = document.getElementById("itemNo1").value+"-"+document.getElementById("itemNo2").value;
	
	var xmlHttp;

	xmlHttp = new XMLHttpRequest();
	xmlHttp.onreadystatechange = checkStatus2;
	xmlHttp.open("GET", "../itm2099/itm2099?itemCd="+findItemNo, false);
	xmlHttp.send(null);

	function checkStatus2(){
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
			var xml = xmlHttp.responseXML;
			var rootNodes = xml.getElementsByTagName("list");
			var rootNode = rootNodes[0];
			var json = JSONConvert(rootNode);
			if (json==null) {
			}else {
				//-----------------------------------------
				//直結看板かチェック
				//-----------------------------------------
				var rsvDiv = json.rsvdiv;

				//直結看板以外の時はメッセージを表示
				if(rsvDiv != "0"){
					alert_Custom("<%=Message.getMessage("WRN01570").replace("$1", "入荷取消")%>");
					return;
				}
				//-----------------------------------------
				//削除チェック
				//-----------------------------------------
				var delDiv = json.deldiv;

				//削除の時はメッセージを表示
				if(delDiv == "1"){
					alert_Custom("<%=Message.getMessage("WRN01500").replace("$1", "入荷取消")%>");
					return;
				}
				//-----------------------------------------
				//在庫チェック
				//-----------------------------------------
				var newStock = json.newstock;
				var useStock = json.usestock;
				
				var arrNum_hid = document.getElementById("arrNum_hid").value;
				//新品在庫＜入荷数ときは、確認メッセージを表示する。
				if(Number(newStock.replace(/,/g,""))<Number(arrNum_hid.replace(/,/g,""))){
					alert_Custom("<%=Message.getMessage("WRN01510")%>");
					return;
				}
				updateDtCheck3();

			}
		}
	}
}

//*************************************************
//AJAX 部分(確定時と発注時の予備品発注Tの更新日を比較)
//*************************************************
function updateDtCheck3(){
	mainForm = document.getElementById("F1");
	//------------------------------------------------------
	//発注Tの確定時と発注時の更新日を比較
	var findOdrNo = document.getElementById("odrNo").value;
	
	var xmlHttp;

	xmlHttp = new XMLHttpRequest();
	xmlHttp.onreadystatechange = checkStatus4;
	xmlHttp.open("GET","../inv2002/inv2002?odrNo="+findOdrNo,false);
	xmlHttp.send(null);

	function checkStatus4(){
		if (xmlHttp.readyState == 4 && xmlHttp.status == 200){
			var xml = xmlHttp.responseXML;
			var rootNodes = xml.getElementsByTagName("list");
			var rootNode = rootNodes[0];
			var json = JSONConvert(rootNode);
			if (json==null) {
			}else {
				var orderUpdateDt = json.updatedt;
				var confirmUdateDt = document.getElementById("updateDt_hid_odr").value;
				//確定時と発注時の更新日を比較
				if(orderUpdateDt == confirmUdateDt || orderUpdateDt == null){
					
					var afterFunc="yesUndoBtn();"
					if (!confirm_Custom3("<%=Message.getMessage("INF01110").replace("$1", "入荷完了").replace("$2","未入荷")%>",afterFunc)){
						return;
					}
				}else{

					alert_Custom("<%=Message.getMessage("WRN01030").replace("$1", "入荷取消")%>");
					//予備品のマスタ情報が既に変更されています。発注を再度やり直して下さい。
					return;
				}

			}
		}
		//------------------------------------------------------
	}
}
//「はい」を押された時
function yesUndoBtn(){
	document.getElementById("undoExe").value = "1";
	mainForm = document.getElementById("F1");
	mainForm.submit();
}

</script>


</head>

<body onLoad="onInit()">
<form name="main" id="F1" action="./inv2000" method="post" class="frmMain"  onsubmit="return false;">
<div id="NumKeyBoardID"></div>
<table style="">
<%
//題名の設定
String headSubName="";
if("3".equals(strOutputCate)){
	headSubName = "完了";
}else if("4".equals(strOutputCate)){
	headSubName = "取消";
}
%>
	<!--HEADER TITLE START -->
	<tr style = "background-color:#e1e1e1;  font-weight: bold;  border-bottom:1px solid #e1e1e1; background: -webkit-gradient(linear, left top, left bottom, from(#e1e1e1), to(#ffffff));　 ">
		<td colspan="2" class ="header_tbl" style = "font-size:22px; height:40px;"  align="left">
			　予備品管理システム (<%=formBean.kojou%>)　　　
			<span style="font-size:30px; text-shadow:2px 2px #666; 	color:#aaa;">直結看板入荷登録画面（<%=headSubName%>）</span>
		</td>
	</tr>
	<!--HEADER TITLE END -->

	<!--メインメニュー画面　START  -->
	<tr style="height:628px; ">
<%
//バックカラーの設定
String backColor="";
if("3".equals(strOutputCate)){
	backColor="background: -webkit-gradient(linear, left top, left bottom, from(#F0FFFF), to(#F0FFFF));";
}else if("4".equals(strOutputCate)){
	backColor="background: -webkit-gradient(linear, left top, left bottom, from(#FFF0F5), to(#FFF0F5));";
}
%>
		<td class="right" style="<%=backColor%>">
			 <!--<div class="mainLine" id = "mainLine" style="display:inline; " ></div>  -->

			<table width ="100%"  class="mainTbl_Right">
				<!--発注 -->
				<tr>
					<td id="" align = "left"   class="selTitle">　Y品番:　
					<input type="text"  class="ReadStyle" name="itemNo1" id="itemNo1" style="width: 50px; height:25px; font-size:15px; color:blue; "  value="<%=formBean.getItemNo1() %>" readonly> -
					<input type="text"  class="ReadStyle" name="itemNo2" id="itemNo2" style="width: 50px; height:25px; font-size:15px; color:blue;"  value="<%=formBean.getItemNo2() %>" readonly>
					</td>

					<td id="" align = "left"   class="selTitle">　発注日:
						<input type="text"  class="ReadStyle" name="odrDt" id="odrDt" style="width: 100px; height:30px; font-size:15px; color:blue;"  value="<%=formBean.getOdrDt().replace("-", "/") %>"  readonly>
					</td>

				</tr>

				<tr>
					<td id="" align = "left"  valign="top"  class="selTitle" colspan="3">　品名:　　
						<textarea class="ReadStyle" name="itemNm" id="itemNm" cols="40" rows="2" style="width:  500px; font-size:15px; color:blue;" readonly><%=formBean.getItemNm() %></textarea>
					</td>
				</tr>
                <tr>
					<td id="" align = "left"  valign="top"  class="selTitle" colspan="3">　型式:　　
						<textarea class="ReadStyle"  name="model" id="model" cols="40" rows="2" style="width:  500px; font-size:15px; color:blue;" readonly><%=formBean.getModel() %></textarea>
					</td>
				</tr>
				<tr>
					<td id="" align = "left"   class="selTitle">　単価:　　
					<input type="text"  class="unitPrice ReadStyle" name="unitPrice" id="unitPrice" style="width: 100px; height:25px; font-size:15px; color:blue;text-align:right;"  value="<%=formBean.getUnitPrice() %>" readonly></td>

					<td id="" align = "left"   class="selTitle">　 　L/T:
					<input type="text"  class="leadTm ReadStyle" name="leadTm" id="" style="width: 100px; height:25px; font-size:15px; color:blue; text-align:right;"  value="<%=formBean.getLeadTm() %>" readonly></td>

					<td id="" align = "left"   class="selTitle">　出庫オーダー:　
						<%
						String strDelvOdr = "";
						Inv2000Bean.PullData[] inputDelvOdrList = formBean.getInputDelvOdrList();
						for (int i = 0; inputDelvOdrList != null && i < inputDelvOdrList.length; i++) {
							Inv2000Bean.PullData data = inputDelvOdrList[i];
							if(data.key.equals(formBean.getDelvOdr())){
								strDelvOdr = data.value;
							}
						}
						%>
						<input type="text" class="ReadStyle" name="strDelvOdr"  id="strDelvOdr"  style="width:100px; height:33px; font-size:15px; color:blue;" value="<%=strDelvOdr %>" readonly>
					</td>
				</tr>
				<tr>
					<td id="" align = "left"   class="selTitle" colspan="2">　入荷数量:
						<input type="text" class="ReadStyle" name="arrNum" id="arrNum" style="width: 100px; height:25px; font-size:15px; color:blue;text-align:right;"  value="" readonly>
						<input type="text"  class="ReadStyle" style="width: 50px; height:25px; font-size:15px; color:blue; text-align:right;"  value="<%=formBean.getArrNum_hid() %>/<%=formBean.getOrderNum() %>" readonly>
						<input type="hidden"  name="arrNum_hid" id="arrNum_hid" value="<%=formBean.getArrNum_hid() %>" readonly>
						<input type="hidden"  name="orderNum_hid" id="orderNum_hid" value="<%=formBean.getOrderNum() %>" readonly>
					</td>

					<td id="" align="left"   class="selTitle">　使用用途:　
						<input type="text" class="ReadStyle" name="strUseMeth"  id="strUseMeth"  style="width:150px; height:30px; font-size:15px; color:blue;" value="<%=formBean.getUseMeth() %>" readonly>
					</td>
				</tr>


				<tr>
					<td id="" align = "left"   class="selTitle">　設備機番:
					<%
					String machineNm = "";
					Inv2000Bean.PullData[] inputMachineNmList = formBean.getInputMachineNmList();
					for (int i = 0; inputMachineNmList != null && i < inputMachineNmList.length; i++) {
						Inv2000Bean.PullData data = inputMachineNmList[i];
						if(data.key.equals(formBean.getMachineNo())){
							machineNm = data.value;
						}
					}
					%>
					<input type="hidden"  class="ReadStyle" name="machineNo" id="machineNo"  value="<%=formBean.getMachineNo() %>" >
					<input type="text"  class="ReadStyle" name="strMachineNo" id="strMachineNo" style="width: 100px; height:25px; font-size:15px; color:blue;"  value="<%=machineNm%>" readonly></td>
					<td id="" align = "left"   class="selTitle">　入荷予定年月日:
					<input type="text"  class="ReadStyle" name="arrPlanDt" id="arrPlanDt" style="width: 100px; height:33px; font-size:15px; color:blue;"  value="<%=formBean.getArrPlanDt().replace("-", "/") %>" readonly></td>
					<td id="" align = "left"   class="selTitle">　入荷年月日:
					<input type="text"  class="ReadStyle" name="arrDt" id="arrDt" style="width: 100px; height:33px; font-size:15px; color:blue;"  value="<%=formBean.getArrDt().replace("-", "/") %>" readonly></td>
				</tr>

				<!--線を引く -->
				<tr><td  colspan="4"><hr></td></tr>

				<tr>
					<td id="" align = "left"   class="selTitle" colspan="2">　発注担当者:
						<%
						String strOdrUsr = "";
						Inv2000Bean.PullData[] inputEmpPullList = formBean.getInputEmpPullList();
						for (int i = 0; inputEmpPullList != null && i < inputEmpPullList.length; i++) {
							Inv2000Bean.PullData data = inputEmpPullList[i];
							if(data.key.equals(formBean.getClassOdrUsr())){
								strOdrUsr = data.value;
							}
						}
						%>
						<input type="text" class="ReadStyle" name="strOdrUsr"  id="strOdrUsr"  style="width:100px; height:30px; font-size:15px; color:blue;" value="<%=strOdrUsr %>" readonly>
						<%
						String strUsrList ="";
						Inv2000Bean.PullData[] inputEmpPullList2 = formBean.getInputEmpPullList2();
						for (int i = 0; inputEmpPullList2 != null && i < inputEmpPullList2.length; i++) {
							Inv2000Bean.PullData data = inputEmpPullList2[i];
							if(data.key2.equals(formBean.getOdrUsr())){
								strUsrList = data.value;
							}
						}
						%>
						<input type="text" class="ReadStyle" name="strUsrList"  id="strUsrList"  style="width:100px; height:30px; font-size:15px; color:blue;" value="<%=strUsrList %>" readonly>
					</td>


					<td id="" align = "right"   class="selTitle">使用者:
						<%
						String strUseUsr = "";
						Inv2000Bean.PullData[] inputUseUsrList = formBean.getInputUseUsrList();
						for (int i = 0; inputUseUsrList != null && i < inputUseUsrList.length; i++) {
							Inv2000Bean.PullData data = inputUseUsrList[i];
							if(data.key.equals(formBean.getUseUsr())){
								strUseUsr = data.value;
							}
						}
						%>
						<input type="text" class="ReadStyle" name="strUseUsr"  id="strUseUsr"  style="width:150px; height:30px; font-size:15px; color:blue;" value="<%=strUseUsr %>" readonly>
					</td>
				</tr>

				<tr>
					<td id="" align = "left"   class="selTitle" colspan="2">　入荷担当者:
						<%
						String strArrUsr = "";	
						Inv2000Bean.PullData[] inputArrPullList = formBean.getInputArrPullList();
						for (int i = 0; inputArrPullList != null && i < inputArrPullList.length; i++) {
							Inv2000Bean.PullData data = inputArrPullList[i];
							if(data.key.equals(formBean.getClassArrUsr())){
								strArrUsr =  data.value;
							}
						}
						%>
						<input type="text" class="ReadStyle" name="arrUsr"  id="arrUsr"  style="width:100px; height:30px; font-size:15px; color:blue;" value="<%=strArrUsr %>" readonly>
						<%
						String strArrList = "";
						Inv2000Bean.PullData[] inputArrPullList2 = formBean.getInputArrPullList2();
						for (int i = 0; inputArrPullList2 != null && i < inputArrPullList2.length; i++) {
							Inv2000Bean.PullData data = inputArrPullList2[i];
							if(data.key2.equals(formBean.getArrUsr())){
								strArrList =  data.value;
							}
						}
						%>
						<input type="text" class="ReadStyle" name="arrList"  id="arrList"  style="width:100px; height:30px; font-size:15px; color:blue;" value="<%=strArrList %>" readonly>
					</td>

				</tr>

				<tr>
					<td></td>
					<td align = "right" >
					</td>
					<td align = "right" >
						<%if("3".equals(strOutputCate)){ %>
						<button onclick="undoBtn();" class="confirmBtn2" >入荷取消</button>　　
						<%} %>
					</td>
					<td align = "right" >
						<button onclick="backBtn('odr3000');" class="confirmBtn" >戻る</button>　
					</td>
				</tr>
			</table>


			<!--ログインMAIN画面　END  -->

		</td>
	</tr>
</table>

	<div class='footer' align='right' style="font-size:35px; background-image: url(../../common/img/toyotaB.png); background-repeat: no-repeat; align:top;" ></div>
    <div class='ImageZone' align='right' style="font-size:20px; align:top"><img id="picfileNm" class="image" src='<%=appMng.getAppConfig("userconfig.imagepath")%><%=formBean.getPicfileNm()%>' height='170px' width='330px'></div>

	<input type="hidden" id="nextPage" name="nextPage" value="">
	<!-- input type="hidden" id="orderExe" name="orderExe" value="">
	<input type="hidden" id="endExe" name="endExe" value="">
	<input type="hidden" id="cancelExe" name="cancelExe" value="" -->
	<input type="hidden" id="undoExe" name="undoExe" value="">
	<input type="hidden" id="updateDtFlg" name="updateDtFlg" value="">

	<input type="hidden" id="outputCate" name="outputCate" value="<%=formBean.getOutputCate() %>">
	<input type="hidden" id="stateFlg" name="stateFlg" value="">
	<input type="hidden" id="odrNo" name="odrNo" value="<%=formBean.getOdrNo() %>">
	<input type="hidden" id="odrMeth" name="odrMeth" value="<%=formBean.getOdrMeth() %>">
	<input type="hidden" id="updateDt_hid" name="updateDt_hid" value="<%=formBean.getUpdateDt_hid() %>">
	<input type="hidden" id="updateDt_hid_arr" name="updateDt_hid_arr" value="<%=formBean.getUpdateDt_hid_arr() %>">
	<input type="hidden" id="updateDt_hid_odr" name="updateDt_hid_odr" value="<%=formBean.getUpdateDt_hid_odr() %>">
	
	<input type="hidden" id="arrListKey" name="arrListKey" value="">
	
	<input type="hidden" id="displayCate" name="displayCate" value="<%=formBean.getDisplayCate() %>">
	
	<!--警告 ポップアップ---------------------------------------------------------------------------- -->
	<div id="allbackgr" class="allbackgr" style="display:none;"></div>
	<div class="opAlertBtn" id = "opAlertBtn" style="display:none;" ></div>
	<div class="opAlertButton" id = "opAlertButton" style="display:none;" ></div>
	<div class="opAlertTop" id = "opAlertTop" style="display:none; font-size:22px;">　予備品管理システム　</div>
	<div class="opAlert" id = "opAlert" style="display:none;"></div>
	<!-- -------------------------------------------------------------------------------------------- -->
</form>
</body>
</html>
